package com.zmzncs.lmtc.module.shop.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmzncs.lmtc.module.shop.pojo.shop_slide_show.ShopSlideShow;
import com.zmzncs.lmtc.module.shop.dao.ShopSlideShowDao;
import com.zmzncs.lmtc.module.shop.pojo.shop_slide_show.ShopSlideShowDTO;
import com.zmzncs.lmtc.module.shop.service.ShopSlideShowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商户-轮播图 服务实现类
 * </p>
 *
 * @author 高博文
 * @since 2021-05-28
 */
@Service
public class ShopSlideShowServiceImpl extends ServiceImpl<ShopSlideShowDao, ShopSlideShow> implements ShopSlideShowService {

    @Autowired
    ShopSlideShowDao shopSlideShowDao;

    @Override
    public void add(Long itemId,Integer itemType,String fileUrl) {
        //查询最大排序编号
        Integer maxSort = shopSlideShowDao.getMaxSort();

        ShopSlideShow show = new ShopSlideShow();
        show.setItemId(itemId);
        show.setItemType(itemType);
        if (maxSort == null){
            maxSort = 0;
        }
        show.setSort(maxSort + 1);
        show.setIsShow(1);
        show.setIsDeleted(0);
        show.setFileUrl(fileUrl);
        shopSlideShowDao.insert(show);
    }

    @Override
    public IPage<ShopSlideShowDTO> getShopSlideShowPage(Integer currentPage, Integer pageSize) {
        currentPage = currentPage == null ? 1 : currentPage;
        pageSize = pageSize == null ? 10 : pageSize;

        Page<Object> page = new Page<>(currentPage, pageSize);
        return shopSlideShowDao.getShopSlideShowPage(page);
    }

    @Override
    public ShopSlideShowDTO getShopSlideShowInfo(Long showId) {
        return shopSlideShowDao.getShopSlideShowInfo(showId);
    }
}
